import scrapy

from duanzi.items import DuanziItem
class DzSpider(scrapy.Spider):
    name = "dz"
    allowed_domains = ["duanzixing.com"]
    start_urls = ["https://duanzixing.com/"]

    def parse(self, response):

        page_url = 'https://duanzixing.com/page/%d/'

        for i in range(1, 11):
            new_url = page_url % i
            # print(new_url)
            yield scrapy.Request(new_url, callback=self.parse_detail)

    def parse_detail(self, response):

        item =  DuanziItem()
        article_list = response.xpath('/html/body/section/div/div/article')
        for article in article_list:
            title = article.xpath('./header/h2/a/text()').extract_first()
            con = article.xpath('./p[2]/text()').extract_first()
            item['title'] = title
            item['con'] = con
            print(item)
            yield item